package com.competition.web.admin.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.competition.param.impl.OrganizeRequestParam;
import com.competition.web.admin.service.IConditionService;
import com.msg.ResponseCode;
import com.response.vo.ResponseModel;
import com.returns.value.ICodeAndData;
import com.unify.type.DepartmentFlatten;

@RestController
@RequestMapping("getSearchCondition")
public class GetSearchConditionController {
	
	private IConditionService service;

	public GetSearchConditionController(IConditionService service) {
		this.service = service;
	}
	
	/**
	 * 获取加盟部二道组织架构
	 * 指定谈判人
	 * @return
	 */
	@PostMapping("organize")
	public ResponseModel<DepartmentFlatten[][]> getOrganize(@RequestBody @Validated OrganizeRequestParam organizeRequestParam, HttpServletRequest httpServletRequest) {
		
		
		ICodeAndData<DepartmentFlatten[][]> organize = this.service.getDesignatedNegotiatorAndInvitationDepartment(
				organizeRequestParam, 
				this.getToken(httpServletRequest)
		);
		
		if (ResponseCode.ERROR.getCode() == organize.getStatus()) {
			return ResponseModel.errorMsg(null, organize.getMsg());
		}
		
		return ResponseModel.success(organize.getData());
	}
	
	private String getToken(HttpServletRequest httpServletRequest) {
		return httpServletRequest.getHeader("Authorization");
	}
}
